<?php


namespace app\api\model;

use app\api\controller\Code;
use think\Db;
use think\Model;

/**
 * 随访记录
 * Class FollowRecordModel
 * @package app\api\model
 *
 */
class FollowRecordModel extends Model
{

    /**
     * 设置表名
     * @var string
     */
    protected $table = 'ah_follow_record';


    /**
     *
     * 添加随访记录信息
     */
    public static function followRecordAdd($params){

        $follow = [

            'user_id'=>$params['user_id'],
            'case_id'=>$params['case_id'],
            'visit_at'=>$params['visit_at'],
            'inspect_imgs'=>$params['inspect_imgs'],
            'visit_info'=>$params['visit_info'],
            'update_at'=>time(),

        ];

        if (isset($params['id']) && $params['id'] > 0){

            return self::where(['id'=>$params['id']])->update($follow);
        }

        return self::insert($follow);
    }


    /**
     *
     * 随访记录详情
     */
    public static function followRecordInfo($id){

        $data = self::where(['id'=>$id])->field('id,visit_at,inspect_imgs,visit_info,create_at')->find();

        #检测报告图片
        if ($data['inspect_imgs']){

            $data['inspect_imgs'] = explode('|',$data['inspect_imgs']);
        }
        return $data;
    }

    /**
     *
     * 删除随访记录
     */
    public static function followRecordDel($id){

        return self::where(['id'=>$id])->delete();
    }

}